import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int len = in.nextInt();
        int min = Integer.MAX_VALUE, max = 0, ret = 0;
        for(int i = 1; i <= len; i++) {
            int n = in.nextInt();
            if(n < min) {
                max = 0;
                min = n;
            }else {
                if(max < n) {
                    max = n;
                    ret = Math.max(max - min, ret);
                }
            }
        }
        System.out.println(ret);
    }
}